<?php

!defined('SYSTEM_INCLUDED') && exit('Access Denied');


Class CommonException extends Exception{
	
	public $errorHeaderTitle = "System Error!";

    public function __construct($message,$code=0)
    {
        parent::__construct($message,$code);
    }
	
    public function __toString()
    {
		$error  = array();
		$error['headerTitle'] = $this->errorHeaderTitle;
        $error['message']   = $this->getMessage();
		
		if (true === DEBUG_MODE){
            $error['messageTip']    = 'Exception Class: '.get_class($this);
            $error['messageTip']   .= '(Code: '.$this->getCode().')';
            $error['messageTip']   .= '<br />File: '.$this->getFile();
            $error['messageTip']   .= ' IN LINE '.$this->getLine();
            $error['messageTip']   .= '<br />Trace Info: '.$this->getTraceAsString();
			$error['messageTip']   .= '<br /><br />Powered By SYSTEM FRAMEWORK [DEBUG MODE]. Version:'.implode(" / ",SysBase::getVersion());
		}else{
			$error['messageTip']   = Config::get('ERROR_MESSAGE_TIP');
			$error['messageTip']   .= '<br /><br />Powered By SYSTEM FRAMEWORK. Version:'.implode(" / ",SysBase::getVersion());
		}
		
		
        echo <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{$error['headerTitle']}</title>
</head>
<body bgcolor="#FFFFFF">
<table cellpadding="0" cellspacing="0" border="0" width="700" align="center" height="85%">
  <tr align="center" valign="middle">
    <td>
    <table cellpadding="10" cellspacing="0" border="0" width="80%" align="center" style="font-family: Verdana, Tahoma; color: #666666; font-size: 11px">
    <tr>
      <td valign="middle" align="center" bgcolor="#EBEBEB">
        <br /><b style="font-size: 16px">{$error['message']}</b>
        <br /><br />{$error['messageTip']}
        <br /><br />
		<a href="javascript:history.back(-1);">Back to Previous Page</a>
        <br /><br />
      </td>
    </tr>
    </table>
    </td>
  </tr>
</table>
</body>
</html>
EOF;
		exit;
    }


}